package com.ruoyi.transfers.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.transfers.domain.WGoodsTransferAccount;
import com.ruoyi.transfers.service.IWGoodsTransferAccountService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 货转记账Controller
 * 
 * @author wzy
 * @date 2024-08-27 15:41:13
 */
@RestController
@RequestMapping("/transfers/account")
public class WGoodsTransferAccountController extends BaseController
{
    @Autowired
    private IWGoodsTransferAccountService wGoodsTransferAccountService;

    /**
     * 查询货转记账列表
     */
    @PreAuthorize("@ss.hasPermi('transfers:account:list')")
    @GetMapping("/list")
    public TableDataInfo list(WGoodsTransferAccount wGoodsTransferAccount)
    {
        startPage();
        List<WGoodsTransferAccount> list = wGoodsTransferAccountService.selectWGoodsTransferAccountList(wGoodsTransferAccount);
        return getDataTable(list);
    }

    /**
     * 导出货转记账列表
     */
    @PreAuthorize("@ss.hasPermi('transfers:account:export')")
    @Log(title = "货转记账", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WGoodsTransferAccount wGoodsTransferAccount)
    {
        List<WGoodsTransferAccount> list = wGoodsTransferAccountService.selectWGoodsTransferAccountList(wGoodsTransferAccount);
        ExcelUtil<WGoodsTransferAccount> util = new ExcelUtil<WGoodsTransferAccount>(WGoodsTransferAccount.class);
        util.exportExcel(response, list, "货转记账数据");
    }

    /**
     * 获取货转记账详细信息
     */
    @PreAuthorize("@ss.hasPermi('transfers:account:query')")
    @GetMapping(value = "/{goodsTransferAccountId}")
    public AjaxResult getInfo(@PathVariable("goodsTransferAccountId") Long goodsTransferAccountId)
    {
        return success(wGoodsTransferAccountService.selectWGoodsTransferAccountByGoodsTransferAccountId(goodsTransferAccountId));
    }

    /**
     * 新增货转记账
     */
    @PreAuthorize("@ss.hasPermi('transfers:account:add')")
    @Log(title = "货转记账", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WGoodsTransferAccount wGoodsTransferAccount)
    {
        wGoodsTransferAccount.setCreateBy(getNickName());
        return toAjax(wGoodsTransferAccountService.insertWGoodsTransferAccount(wGoodsTransferAccount));
    }

    /**
     * 修改货转记账
     */
    @PreAuthorize("@ss.hasPermi('transfers:account:edit')")
    @Log(title = "货转记账", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WGoodsTransferAccount wGoodsTransferAccount)
    {
        wGoodsTransferAccount.setUpdateBy(getNickName());
        return toAjax(wGoodsTransferAccountService.updateWGoodsTransferAccount(wGoodsTransferAccount));
    }

    /**
     * 删除货转记账
     */
    @PreAuthorize("@ss.hasPermi('transfers:account:remove')")
    @Log(title = "货转记账", businessType = BusinessType.DELETE)
	@DeleteMapping("/{goodsTransferAccountIds}")
    public AjaxResult remove(@PathVariable Long[] goodsTransferAccountIds)
    {
        return toAjax(wGoodsTransferAccountService.deleteWGoodsTransferAccountByGoodsTransferAccountIds(goodsTransferAccountIds));
    }
}
